/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package webClient;

import engine.Singleton;
import java.net.URL;
import tictactoe.SmallField;

/**
 *
 * @author User
 */
public class WebPages {
  
  public static String connect()
  {
    String str = "<form action=\"\" method=\"get\" name=\"login\"><p>IP:"
            + "<input name=\"adrr\" type=\"text\" /> </p><p>PORT: <input name=\"port\" type=\"text\" />"
            + "</p><p>Login:<input name=\"login\" type=\"text\" /></p><p>"
            + "<input type=\"submit\" name=\"Submit\" value=\"Connect\" /></p></form>";
    return str;
  }
  
  public static String listOfPlaer()
  {
    String str = "<meta HTTP-EQUIV=\"Refresh\" Content=\"1; URL=http://localhost:7777/name\">"
            + "<html><body><h1>Connect </h1> "
          //  + " <h1><a href=\"name\">Начать игру</a> </h1>"
            + "</body></html>";
    return str;
  }
  
  public static String list()
  {
          
          
    for (int j=0; j<3; j++)
    {
      for (int i = 0; i < 3; i++) {
        Singleton.fig[j][i] = 0;
        
      }
    }      
    String list = ""
           // + "<meta HTTP-EQUIV=\"Refresh\" Content=\"1; URL=http://localhost:7777/name\">" 
            + Singleton.invite;
    for (String s : Singleton.Clientusers){
      list += "<h4><a href=\"list." + s + "\">" + s + "</a> </h4>";
    }
    String str = "<h3>Список игроков </h3>" + list ;
   // System.out.println(str);
    return str;
  }
  
  public static String update() {
    String str = "<meta HTTP-EQUIV=\"Refresh\" Content=\"1; URL=http://localhost:7777/update\">"
       //     + "<html><body><h1><a href=\"update\">Обновить</a> </h1>"
            + "</body></html>";
    return str;
  }

 public static String update2(String stat) {
    String str = "<html><body><h1>" + stat + "</h1>" + list() + " </body></html>";
    return str;
  }

  public static String startPlay() {
   // URL location = WebPages.class.getProtectionDomain().getCodeSource().getLocation(); 
    

    String str = ""
            + "<meta HTTP-EQUIV=\"Refresh\" Content=\"1; URL=http://localhost:7777/plaup\">"
            + "<html><body>"
          + "  <table width=\"300\" border=\"1\">"
            + "<tr>"
              + "<td height=\"100\">" + setLink(0,0) + "<img src=\"" + setFig(0,0) + "\" width=\"90\" height=\"90\" border=\"0\" />" + setLink2(0,0) + "</td>"
              + "<td>" + setLink(0,1) + "<img src=\"" + setFig(0,1) + "\" width=\"90\" height=\"90\" border=\"0\" />" + setLink2(0,1) + "</td>"
              + "<td>" + setLink(0,2) + "<img src=\"" + setFig(0,2) + "\" width=\"90\" height=\"90\" border=\"0\" />" + setLink2(0,2) + "</td>"
            + "</tr>"
            + "<tr>"
              + "<td height=\"100\">" + setLink(1,0) + "<img src=\"" + setFig(1,0) + "\" width=\"90\" height=\"90\" border=\"0\" />" + setLink2(1,0) + "</td>"
              + "<td>" + setLink(1,1) + "<img src=\"" + setFig(1,1) + "\" width=\"90\" height=\"90\" border=\"0\" />" + setLink2(1,1) + "</td>"
              + "<td>" + setLink(1,2) + "<img src=\"" + setFig(1,2) + "\" width=\"90\" height=\"90\" border=\"0\" />" + setLink2(1,2) + "</td>"
            + "</tr>"
            + "<tr>"
              + "<td height=\"100\">" + setLink(2,0) + "<img src=\"" + setFig(2,0) + "\" width=\"90\" height=\"90\" border=\"0\" />" + setLink2(2,0) + "</td>"
              + "<td>" + setLink(2,1) + "<img src=\"" + setFig(2,1) + "\" width=\"90\" height=\"90\" border=\"0\" />" + setLink2(2,1) + "</td>"
              + "<td>" + setLink(2,2) + "<img src=\"" + setFig(2,2) + "\" width=\"90\" height=\"90\" border=\"0\" />" + setLink2(2,2) + "</td>"
            + "</tr>"
          + "</table>"
            + "<h3>"  + Singleton.gameStatus + "</h3>"
           // + "<h1><a href=\"plaup\">Обновить</a> </h1>"
            
            + "</body></html>";
    //System.out.println(str);
    return str;
  }
  
  public static String status()
  {
    String str = ""
            + "<meta HTTP-EQUIV=\"Refresh\" Content=\"1; URL=http://localhost:7777/status\">"
            + "<html><body>"
            + "<h2>"  + Singleton.gameStatus + "</h2>"
            + "</body></html>";
    return str;
  }
  
  public static String mainWindow() {
    String str = ""
            + "<table width=\"550\" height=\"400\"  border=\"1\" bordercolor=\"#000000\"><tr>"
            + "<td width=\"350\" rowspan=\"3\">"
            + "<iframe src=\"/plaup\" width=\"350\" height=\"450\"  scrolling=\"auto\" frameborder=\"0\"></iframe>"
            + "</td><td width=\"200\">"
            + connect()
            + "</td></tr><tr>"
            + "<td>" + list() + "</td>"
            + "</tr><tr>"
            + "<td>"
            + "<h3><a href=\"reflis\">Обновить список</a></h3>"
         //   + "<iframe src=\"/status\" width=\"150\" height=\"150\"  scrolling=\"auto\" frameborder=\"0\"></iframe>"
          //  + " <h4><a href=\"name\">Начать новую игру</a> </h4>"
            + "</td></tr></table>";
    return str;
  }
  
  private static String setFig(int row, int col)
  {
    String path = "http://vira7.com/temp/0.JPG";
    int dig;
    dig = Singleton.fig2[row][col];
    if (dig == 0)
      path = "http://vira7.com/temp/0.JPG";
    if (dig == 1)
      path = "http://vira7.com/temp/1.JPG";
    if (dig == 2)
      path = "http://vira7.com/temp/2.JPG";
    return path;
  }
  
  private static String setLink(int row, int col)
  {
    String link = "";
    if (Singleton.fig2[row][col] == 0){
        if(Singleton.spaly){
          link = "<a href=\"step" + row + col + "\">";
        }
      
    }
    return link;
  }
  
   private static String setLink2(int row, int col)
  {
    String link = "";
    if (Singleton.fig2[row][col] == 0){
        if(Singleton.spaly){
          link = "</a>";
        }
    }
    return link;
  }
  
}
